//利用replace函数，将"foo=1&foo=2&blah=a&blah=b&foo=3"转换成"foo=1,2,3&blah=a,b"
function compress(source) {
    const keys = {}
    source.replace(
        /([^=&]+)=([^&]*)/g,
        function(_, key, value) {
            keys[key] = (keys[key] ? keys[key] + ',' : '') + value
            return ''
        }
    )
    const result = []
    for (let key in keys) {
        result.push(key + '=' + keys[key])
    }
    return result.join('&')
}

module.exports = {compress}
